package main

import "fmt"

type Usb interface {
	Start()
	Stop()
}

type Phone struct {
	Name string
}

func (p Phone) Start() {
	fmt.Printf("手机%s开始工作....\n", p.Name)
}
func (p Phone) Stop() {
	fmt.Printf("手机%s停止工作....\n", p.Name)
}

type Camera struct {
	Name string
}

func (c Camera) Start() {
	fmt.Printf("相机%s开始工作....\n", c.Name)
}
func (c Camera) Stop() {
	fmt.Printf("相机%s停止工作....\n", c.Name)
}

type Computer struct {
}

func (c Computer) Working(usb Usb) {
	usb.Start()
	usb.Stop()
}

func main() {
	// 定义usb接口数组，可以存放phone和camera的结构体变量
	// 体现多态数组
	var usbSlice []Usb = make([]Usb, 0)
	usbSlice = append(usbSlice, Phone{"苹果"})
	usbSlice = append(usbSlice, Camera{"索尼"})
	usbSlice = append(usbSlice, Phone{"华为"})
	for _, usb := range usbSlice {
		Computer{}.Working(usb)
	}
}
